﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="MDT_Metro_monitoring.ServerDetailPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MDT_Metro_monitoring"
    xmlns:common="using:MDT_Metro_monitoring.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>

        <!-- Collection d'éléments affichés par cette page -->
        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"/>
    </Page.Resources>

    <!--
        La grille sert de panneau racine à la page, permettant de définir deux lignes :
        * La ligne 0 qui contient le bouton Précédent et le titre de la page
        * La ligne 1 qui contient le reste de la page
    -->
    <Grid DataContext="{Binding Server}" Style="{StaticResource MDTRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Bouton Précédent et titre de la page -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Id}" Style="{StaticResource PageHeaderTextStyle}" Grid.Column="1"/>
        </Grid>

        <!-- Grille de défilement horizontal utilisée dans la plupart des états d'affichage -->
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Items In Group"
            TabIndex="1"
            Grid.Row="1"
            Margin="0,-14,0,0"
            Padding="120,0,120,50"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource ServerItemTemplate}"
            SelectionMode="None"
            ItemClick="itemGridView_ItemClick"
            IsItemClickEnabled="True">

            <GridView.Header>
                <StackPanel Width="480" Margin="5,4,14,0">
                    <TextBlock Text="{Binding Id}" Margin="0,0,18,20" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60"/>
                    <Image Source="{Binding Image}" Height="300" Margin="0,0,18,20" Stretch="UniformToFill"/>
                    <StackPanel>
                        <RichTextBlock Margin="5,5,5,5" Style="{StaticResource BasicRichTextStyle}">
                            <Paragraph FontSize="20" >
                                <Run Text="Client installation completion: "/>
                                <Run Text="{Binding PercentCompleteStr}"/>
                                <LineBreak/>
                            </Paragraph>
                            
                            <Paragraph FontSize="20">
                                <Run Text="{Binding data1String}"/>
                                <Run Text="{Binding data1Text}"/>
                                <LineBreak/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="{Binding ErrorColor}">
                                <Run Text="{Binding data2String}"/>
                                <Run Text="{Binding data2Text}"/>
                                <LineBreak/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="{Binding WarningColor}">
                                <Run Text="{Binding data3String}"/>
                                <Run Text="{Binding data3Text}"/>
                                <LineBreak/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="White">
                                <Run Text="Installed Clients:"/>
                                <Run Text="{Binding NbClientInstalled}"/>
                                <LineBreak/>
                            </Paragraph>
                        </RichTextBlock>
                    </StackPanel>
                </StackPanel>
            </GridView.Header>
            <GridView.ItemContainerStyle>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Margin" Value="52,0,0,10"/>
                </Style>
            </GridView.ItemContainerStyle>
        </GridView>

<!-- Grille de défilement horizontal utilisée dans la plupart des états d'affichage -->
        <GridView
            x:Name="itemGridViewPortrait"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Items In Group"
            TabIndex="1"
            Grid.Row="1"
            Margin="0,-14,0,0"
            Padding="120,0,120,50"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource ServerItemTemplate}"
            SelectionMode="None"
            ItemClick="itemGridView_ItemClick"
            IsItemClickEnabled="True">

            <GridView.Header>
                <StackPanel Width="480" Margin="5,4,14,0">
                    <TextBlock Text="{Binding Id}" Margin="0,0,18,20" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60"/>
                    <Image Source="{Binding Image}" Height="300" Margin="0,0,18,20" Stretch="UniformToFill"/>
                    <StackPanel>
                        <RichTextBlock Margin="5,5,5,5" Style="{StaticResource BasicRichTextStyle}">
                            <Paragraph FontSize="20" >
                                <Run Text="Client installation completion: "/>
                                <Run Text="{Binding PercentCompleteStr}"/>
                                <LineBreak/>
                            </Paragraph>

                            <Paragraph FontSize="20">
                                <Run Text="{Binding data1String}"/>
                                <Run Text="{Binding data1Text}"/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="{Binding ErrorColor}">
                                <Run Text="{Binding data2String}"/>
                                <Run Text="{Binding data2Text}"/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="{Binding WarningColor}">
                                <Run Text="{Binding data3String}"/>
                                <Run Text="{Binding data3Text}"/>
                            </Paragraph>
                            <Paragraph FontSize="20" Foreground="White">
                                <Run Text="Installed Clients:"/>
                                <Run Text="{Binding NbClientInstalled}"/>
                            </Paragraph>
                        </RichTextBlock>
                    </StackPanel>
                </StackPanel>
            </GridView.Header>
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>

            <GridView.ItemContainerStyle>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Margin" Value="52,0,0,10"/>
                </Style>
            </GridView.ItemContainerStyle>
        </GridView>
        
        <!-- Liste de défilement vertical utilisée uniquement lorsque l'état d'affichage a la valeur Snapped -->
        <ListView
            x:Name="itemListView"
            AutomationProperties.AutomationId="ItemListView"
            AutomationProperties.Name="Items In Group"
            TabIndex="1"
            Grid.Row="1"
            Visibility="Collapsed"
            Padding="10,0,0,60"
            ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
            ItemTemplate="{StaticResource ServerItemTemplate}"
            ItemClick="itemGridView_ItemClick"
            IsItemClickEnabled="True"
            SelectionMode="None">

            <ListView.Header>
                
                    <StackPanel Margin="5,4,14,0">
                        <TextBlock Text="{Binding Id}" Margin="0,0,18,20" Style="{StaticResource SubheaderTextStyle}" MaxHeight="60"/>
                        <StackPanel>
                            <RichTextBlock Margin="5,5,5,5" Style="{StaticResource BasicRichTextStyle}">
                                <Paragraph FontSize="20" >
                                    <Run Text="Client installation completion: "/>
                                    <Run Text="{Binding PercentCompleteStr}"/>
                                </Paragraph>

                                <Paragraph FontSize="20">
                                    <Run Text="{Binding data1String}"/>
                                    <Run Text="{Binding data1Text}"/>
                                </Paragraph>
                                <Paragraph FontSize="20" Foreground="{Binding ErrorColor}">
                                    <Run Text="{Binding data2String}"/>
                                    <Run Text="{Binding data2Text}"/>
                                </Paragraph>
                                <Paragraph FontSize="20" Foreground="{Binding WarningColor}">
                                    <Run Text="{Binding data3String}"/>
                                    <Run Text="{Binding data3Text}"/>
                                </Paragraph>
                                <Paragraph FontSize="20" Foreground="White">
                                    <Run Text="Installed Clients:"/>
                                    <Run Text="{Binding NbClientInstalled}"/>
                                </Paragraph>
                            </RichTextBlock>
                        </StackPanel>
                    </StackPanel>                
            </ListView.Header>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Les états visuels reflètent l'état d'affichage de l'application -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100,0,90,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridViewPortrait" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                
                <VisualState x:Name="Filled"/>

                <!-- La totalité de la page respecte la convention de marge étroite de 100 pixels du mode Portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridViewPortrait" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100,0,90,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridViewPortrait" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    Le bouton Précédent et le titre ont un style différent lorsque l'état d'affichage a la valeur Snapped, et la représentation de liste est remplacée
                    par la grille affichée dans tous les autres affichages
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemGridViewPortrait" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
